﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.ComponentModel.Design.Serialization;
using System.Reflection;

namespace ProgNetComponentsDx.Shortcut.Design
{
    public class ShortcutGroupTypeConverter : ProgNetComponents.Design.TypeConverters.CollectionItemTypeConverter<ShortcutGroup>
    {
        protected override ConstructorInfo GetConstructor(ShortcutGroup item)
        {

            if (item.Groups == null || item.Groups.Count == 0)
            {
                if (item.Items == null || item.Items.Count == 0)
                {
                    return item.GetType().GetConstructor(new Type[] { typeof(string) });
                }
                else
                {
                    return item.GetType().GetConstructor(new Type[] { typeof(string), typeof(Shortcut[]) });
                }
            }
            else
            {
                if (item.Items == null || item.Items.Count == 0)
                {
                    return item.GetType().GetConstructor(new Type[] { typeof(string), typeof(ShortcutGroup[]) });
                }
                else
                {
                    return item.GetType().GetConstructor(new Type[] { typeof(string), typeof(ShortcutGroup[]), typeof(Shortcut[]) });
                }
            }
        }

        protected override object[] GetConstructorParamters(ShortcutGroup item)
        {

            if (item.Groups == null || item.Groups.Count == 0)
            {
                if (item.Items == null || item.Items.Count == 0)
                {
                    return new object[] { item.Name };
                }
                else
                {
                    return new object[] { item.Name, item.Items.ToArray() };
                }
            }
            else
            {
                if (item.Items == null || item.Items.Count == 0)
                {
                    return new object[] { item.Name, item.Groups.ToArray() };
                }
                else
                {
                    return new object[] { item.Name, item.Groups.ToArray(), item.Items.ToArray() };
                }
            }
        }
    }
}
